<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>isEventSupported</title>
    <style type="text/css" media="screen">
      span { padding: 0 0.5em; }
    </style>
  </head>
  <body>
    <script type="text/javascript">
    
      var isEventSupported = (function(){
        var TAGNAMES = {
          'select':'input','change':'input',
          'submit':'form','reset':'form',
          'error':'img','load':'img','abort':'img'
        }
        function isEventSupported(eventName) {
          var el = document.createElement(TAGNAMES[eventName] || 'div');
          eventName = 'on' + eventName;
          // IE skips "unload" and WebKit - "unload" and "resize" - when using `setAttribute`
          // `in` catches these offenders
          var isSupported = (eventName in el);
          if (!isSupported) {
            el.setAttribute(eventName, 'return;');
            isSupported = typeof el[eventName] == 'function';
          }
          el = null;
          return isSupported;
        }
        return isEventSupported;
      })();
    
      function w(name) {
        document.write(name + ': ' + (
          isEventSupported(name) 
            ? '<span style="background-color:green;color:white;">true</span>' 
            : '<span style="background-color:red;color:white;">false</span>'
          ) + '<br>');
      }
      
      document.write('<pre>' + isEventSupported + '</pre><br><br>');
      
      document.write('<h2>Mouse events:</h2>');
      
      w('click');
      w('dblclick');
      w('mousedown');
      w('mouseup');
      w('mouseover');
      w('mousemove');
      w('mouseout');
      
      document.write('<h2>Key events:</h2>');
      
      w('keypress');
      w('keydown');
      w('keyup');
      
      document.write('<h2>HTML events</h2>');
      
      w('load');
      w('unload');
      w('abort');
      w('error');
      w('resize');
      w('scroll');
      
      document.write('<h2>Form events:</h2>');
      
      w('select');
      w('change');
      w('submit');
      w('reset');
      w('focus');
      w('blur');
      
      document.write('<h2>Should exist in MSHTML DOM:</h2>');
      
      w('cut');
      w('copy');
      w('paste');
      w('beforecut');
      w('beforecopy');
      w('beforepaste');
      w('afterupdate');
      w('beforeupdate');
      w('cellchange');
      w('dataavailable');
      w('datasetchanged');
      w('datasetcomplete');
      w('errorupdate');
      w('rowenter');
      w('rowexit');
      w('rowsdelete');
      w('drag');
      w('dragstart');
      w('dragenter');
      w('dragover');
      w('dragleave');
      w('dragend');
      w('drop');
      w('selectstart');
      w('mouseenter');
      w('mouseleave');
      w('activate');
      w('beforeactivate');
      w('deactivate');
      w('beforedeactivate');
      w('touchmove');
      w('touchdown');
      w('touchup');
      
      document.write('<h2>Should never exist:</h2>');
      
      w('click2');
      w('foobarbaz');
      
      document.write('<h2>Should not exist in Opera <=10a</h2>');
      
      w('contextmenu');
      
    </script>

  </body>
</html>